// ----------------------------------------------------------------------------
// serialize_type.h
// ----------------------------------------------------------------------------
/*
 Description:
 シリアライズデータを構成するデータ型を定義する為の基底クラス.
 */
#pragma once
#include <stddef.h>
#include <fw/base/core/stdinteger.h>
#include <fw/base/runtime/hash.h>
#include <fw/base/serialize/serialize_dictionary.h>
#include <fw/base/serialize/serialize_status.h>

namespace fw
{
	class ByteWriter;
	class ByteReader;
	
	class SerializeAllocator;
	class SerializeScalarValue;
	class SerializePointerValue;
	class SerializeScalarType;
	class SerializePointerType;
	class SerializeCompoundType;
	class SerializeSchema;
	
	class SerializeType
	{
	protected:
		enum ByteCode
		{
			kByteCode_Compound,
			kByteCode_Scalar,
		};
		
	public:
		virtual ~SerializeType()
		{
		}
		
		virtual SerializeStatus		ConvertOne(char*						dstData,
											   const char*					srcData,
											   const SerializeType*			srcType,
											   class SerializeAllocator&	allocator,
											   int							arrayCount=1) const = 0;
		virtual size_t				GetSize()      const = 0;
		virtual size_t				GetAlignment() const = 0;
		
		virtual bool				IsTerminal(const char*					data,
											   const SerializeScalarValue&	terminatorValue,
											   Hash							terminatorName) const = 0;
		
		virtual SerializeStatus		FixUp(SerializeSchema& schema) = 0;
		
		virtual const SerializePointerType*		AsPointerType() const
		{
			return nullptr;
		}

		virtual const SerializeScalarType*		AsScalarType()  const
		{
			return nullptr;
		}
		
		virtual const SerializeCompoundType*	AsCompoundType() const
		{
			return nullptr;
		}
	
		virtual bool				IsBuiltIn	() const = 0;
		virtual void				Write		(ByteWriter& writer) const = 0;
		static  SerializeType*		ReadNew		(ByteReader& reader);
		
		virtual uint64_t			GetChecksum	(uint64_t basis) const = 0;
	}; // class SerializeType
	
	
	
} // namespace fw
